<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>CareNote-UserUpdate</title>
    <link rel="stylesheet" type="text/css" href="../../../static/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="../../../static/css/add.css"/>
</head>
<style>
    .light {
        font-size: 20px;
        color: #fefefe;
        text-shadow: 0 0 0.5em #0ae642, 0 0 0.2em #5c5c5c;
    }
</style>
<body>
<div id="app" class="light" style="text-align:center;">
    <div class="header">
        <span>修改模板信息</span>
    </div>
    <div class="content" >
        <table >
            <tr>
                <td class="text-right">名字</td>
                <td class="content_right"><input class="input inline-input" id="oldName" placeholder="请输入Email"> <span
                        class="btn btn-info" id="findByPhone">立即查找</span></td>
            </tr>
        </table>
    </div>
    <div class="header">
        <span>查找信息如下</span>
    </div>
    <div class="content" >
        <table>
            <tr>
                <td class="text-right">该模板信息</td>
                <td class="content_right"><label>
                    <input readOnly="readOnly" class="input" id="id">
                </label>
                </td>
            </tr>
            <tr>
                <td class="text-right">名字</td>
                <td class="content_right"><label>
                    <input class="input" id="name" placeholder="请输入名字">
                </label></td>
            </tr>
            <tr>
                <td class="text-right">天气</td>
                <td class="content_right"><label>
                    <input class="input" id="status" placeholder="请输入天气">
                </label></td>
            </tr>
            <tr>
                <td class="text-right">温度</td>
                <td class="content_right"><label>
                    <input class="input" id="temp" placeholder="请输入温度">
                </label></td>
            </tr>
            <tr>
                <td class="text-right">早安</td>
                <td class="content_right"><label>
                    <input class="input" id="morning" placeholder="请输入早安">
                </label></td>
            </tr>
            <tr>
                <td class="text-right">午安</td>
                <td class="content_right"><label>
                    <input class="input" id="noon" placeholder="请输入午安">
                </label></td>
            </tr>
            <tr>
                <td class="text-right">晚安</td>
                <td class="content_right"><label>
                    <input class="input" id="evening" placeholder="请输入晚安">
                </label></td>
            </tr>
            <tr>
                <td class="text-right">权限</td>
                <td class="content_right"><label>
                   <select id="uId" class="input" >
                       <option id="oldUID">原用户ID</option>
                       <option value="-3">停用</option>
                       <option value="-4">删除</option>
                       <option value="-2">女性模板</option>
                       <option value="-1">男性模板</option>
                       <option value="0">中性模板</option>
                   </select>
                </label></td>
            </tr>
            <tr>
                <td></td>
                <td class="content_right">
                    <span class="btn btn-info" id="user_update">立即修改</span>
                    <span class="btn">重置</span></td>
            </tr>
        </table>
    </div>
</div>
</body>
<script src="../../../static/js/jquery2.1.4.js"></script>
<script src="../../../static/layer/layer.js"></script>
<script>
    $(".header:eq(1),.content:eq(1)").hide();
    let userId = null;
    $(function () {
        $("#findByPhone").click(function () {
            const oldName = $.trim($("#oldName").val());
            if (oldName===""||oldName.length===0){
                layer.msg("查询信息不能为空！");
                return;
            }
            const windowId = layer.load();
            $.getJSON("/admin/module", {name: oldName}, function (data) {
                layer.close(windowId);
                //data:{"status":0,"result":"查询成功","data":{"id":2,"number":"124","username":"张三","userPhone":"13843838438","company":"京东快递","code":"213456","inTime":"Jul 21, 2020, 4:26:21 PM","status":0,"sysPhone":"18888888888"}}
                layer.msg(data.result);
                if (data.status === 200) {
                    $(".header:eq(1),.content:eq(1)").fadeIn(1000);
                    var m = data.data;
                    $("#name").val(m.name);
                    $("#id").val(m.id);
                    $("#status").val(m.status);
                    $("#temp").val(m.temp);
                    $("#morning").val(m.morning);
                    $("#noon").val(m.noon);
                    $("#evening").val(m.evening);
                    $("#uId").val(m.uId);
                    $("#oldUID").val(m.uId);
                    $("#oldUID").html("原归属："+m.uId);
                }
            })
        });
        $("#user_update").click(function () {
            var id = $("#id").val();
            var status = $.trim($("#status").val());
            var temp = $.trim($("#temp").val());
            var name = $.trim($("#name").val());
            var morning = $.trim($("#morning").val());
            var noon = $.trim($("#noon").val());
            var evening = $.trim($("#evening").val());
            var uId = $.trim($("#uId").val());
            if(name===""||name.length===0||name.length>15){
                layer.msg("注意：名字不可为空！且不可超过15字");
                return ;
            }
            const windowId = layer.load();
            $.post("/admin/module", {
                id:id,status:status,temp:temp,morning:morning,name:name,noon:noon,evening:evening,uId:uId
            }, function (data) {
                layer.close(windowId);
                layer.msg(data.result);
                if (data.status === 0) {
                    //修改成功
                    $("input").val("");
                } else {
                    //失败
                }
            });

            return false;
        });
    });
</script>
</html>
